Conditions | 4 |
Paths | 8 |
Total Lines | 63 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | 'use strict' |
||
13 | module.exports = function (slug) { |
||
14 | var template = 'basic' |
||
15 | |||
16 | var userName = (util.getSystemUsername() || 'user').toLowerCase() |
||
17 | if (slug.match(/^[a-z0-9-]+\/[a-z0-9-]+$/)) { |
||
18 | userName = slug.split('/')[0] |
||
19 | slug = slug.split('/')[1] |
||
20 | } |
||
21 | |||
22 | if (!slug.match(/^[a-z0-9-]+$/)) { |
||
23 | output.err('Module name should only contain lowercase letters, numbers and dashes.') |
||
24 | return |
||
25 | } |
||
26 | |||
27 | var repo = 'includable-modules/starter-' + template |
||
28 | var stopSpinner = output.wait('Cloning ' + repo) |
||
29 | |||
30 | try { |
||
31 | fs.mkdirSync(slug) |
||
32 | Git.Clone('https://github.com/' + repo, slug) |
||
33 | .then(function () { |
||
34 | stopSpinner(true) |
||
35 | |||
36 | // Write module.json |
||
37 | var json = util.moduleJSON(slug, userName, name({ |
||
38 | type: 'global' |
||
39 | }), email({ |
||
40 | type: 'global' |
||
41 | }), jsonfile.readFileSync(path.join(slug, 'module.json'))) |
||
42 | fs.writeFileSync(path.join(slug, 'module.json'), JSON.stringify(json, null, 3), 'utf8') |
||
43 | fs.writeFileSync(path.join(slug, 'composer.json'), JSON.stringify({ |
||
44 | 'require': {} |
||
45 | }, null, 3), 'utf8') |
||
46 | |||
47 | // Remove stock files |
||
48 | try { fs.unlinkSync(path.join(slug, 'LICENSE.md')) } catch (e) {} |
||
49 | try { fs.unlinkSync(path.join(slug, 'LICENSE')) } catch (e) {} |
||
1 ignored issue
–
show
|
|||
50 | try { fs.unlinkSync(path.join(slug, 'README')) } catch (e) {} |
||
1 ignored issue
–
show
|
|||
51 | try { rimraf.sync(path.join(slug, '.git')) } catch (e) {} |
||
1 ignored issue
–
show
|
|||
52 | |||
53 | // Write readme.md |
||
54 | fs.writeFileSync(path.join(slug, 'README.md'), '# ' + |
||
55 | util.boxNameDisplay(slug) + '\n\nA Incluable app for ' + util.boxNameDisplay(slug) + '.', 'utf8') |
||
56 | |||
57 | // Git init |
||
58 | var gitSpinner = output.wait('Initializing local Git repository') |
||
59 | Git.Repository.init(path.resolve(slug), 0).then(function () { |
||
60 | gitSpinner(true) |
||
61 | }) |
||
62 | |||
63 | // Download IDE helper |
||
64 | var ideSpinner = output.wait('Downloading code completion helper') |
||
65 | util.downloadHelper(function () { |
||
66 | ideSpinner(true) |
||
67 | }, slug) |
||
68 | }) |
||
69 | .catch(function (e) { |
||
70 | stopSpinner(e) |
||
71 | }) |
||
72 | } catch (e) { |
||
73 | stopSpinner(e) |
||
74 | } |
||
75 | } |
||
76 |